//
// Created by 黄扬航 on 2023/4/19.
//

#ifndef SNAKE_V1_00_SNAKE_H
#define SNAKE_V1_00_SNAKE_H
#include"Point.h"
#include"Control.h"
#include<deque>
#include<stdlib.h>
#include <ctime>
enum SnakeStatusBack {
    Grow = 0, Same, Died
};
enum SnakeMove {
    Right = 6,Left=4,Up=8,Down=5
};
class Snake {
public:
    std::deque<Point::Item> _Snake;
    Snake() {
        Point Pointer=Point::getInstance();
        srand(time(NULL));
        int InitX = rand() % (MaxLength - 5), InitY = rand() % (MaxWidth-2);
        if (InitX == 0) InitX = 2; if (InitY == 0 || InitY) InitY = 4;
        const int Index = InitX + MaxLength * (InitY);
        for (int i = 1; i <= 3; i++)
        {
            int Tempx = InitX;
            Tempx += i;
            Pointer.PointItems[Index + i].X = Tempx; Pointer.PointItems[Index + i].Y = InitY; Pointer.PointItems[Index + i].IsSnake = true;
            if (i == 3)
                Pointer.PointItems[Index + i].Heading = SnakeMove::Right;
            _Snake.push_back(Pointer.PointItems[Index + i]);
        }
    }
    void SnakeGrow(Point::Item a);
    void PrintSnake();
    bool SnakeMove();//自然移动
    bool SnakeMove(int Operation);//操作移动
    static SnakeStatusBack SnakeStatus(int HeadingX, int HeadingY);
    bool CoordinateControl(Point::Item &TempTail,Point::Item &TempTop,int Operation);
    bool CoordinateControl(Point::Item &TempTail,int Index,int Operation);
    static int CurrentScore;
    static int SnakeSize;
};


#endif //SNAKE_V1_00_SNAKE_H
